package vip.xiaonuo.modular.business.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.business.param.BiIndexData.QueryParam;
import vip.xiaonuo.modular.manage.biindexdatasum.entity.BiIndexDataSum;
import vip.xiaonuo.modular.manage.biindexdatasum.param.BiIndexDataSumParam;
import vip.xiaonuo.modular.manage.biindexdatasum.param.QueryIndexParam;
import vip.xiaonuo.modular.manage.biindexdatasum.service.BiIndexDataSumService;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "营商环境")
@RestController
public class IndexDataSumController {

    @Resource
    private BiIndexDataSumService indexDataSumService;

    @ApiOperation("首页默认数据")
    @PostMapping("/business/index/findDefaultData")
    @BusinessLog(title = "获取默认指标数据", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findDefaultData(@RequestBody QueryIndexParam param){
        JSONObject result = indexDataSumService.findDefaultIndexData(param);
        return new SuccessResponseData(result);
    }

    @ApiOperation("营商指数排名与趋势分析")
    @PostMapping("/business/index/findRankList")
    @BusinessLog(title = "营商指数排名与趋势分析", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findRankList(@RequestBody QueryIndexParam param){
        JSONObject result = indexDataSumService.findRankList(param);
        return new SuccessResponseData(result);
    }

    @ApiOperation("营商指数详细分析")
    @PostMapping("/business/index/findIndexDetailList")
    @BusinessLog(title = "营商指数详细分析", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findIndexDetailList(@RequestBody QueryIndexParam param){
        JSONObject result = indexDataSumService.findAllIndexData(param);
        return new SuccessResponseData(result);
    }

    @ApiOperation("营商指数详细分析查询")
    @PostMapping("/business/index/findIndexDetailData")
    @BusinessLog(title = "营商指数详细分析查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findIndexDetailData(@RequestBody QueryIndexParam param){
        JSONObject result = indexDataSumService.findIndexDetailData(param);
        return new SuccessResponseData(result);
    }

    @ApiOperation("二级营商指数查询")
    @PostMapping("/business/index/findSecondIndexData")
    @BusinessLog(title = "二级营商指数查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findSecondIndexData(@RequestBody QueryIndexParam param){
        JSONObject result = indexDataSumService.findSecondIndexData(param);
        return new SuccessResponseData(result);
    }

    @ApiOperation("三级营商指数查询")
    @PostMapping("/business/index/findThirdIndexData")
    @BusinessLog(title = "三级营商指数查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findThirdIndexData(@RequestBody QueryIndexParam param){
        JSONObject result = indexDataSumService.findThirdIndexData(param);
        return new SuccessResponseData(result);
    }

    @ApiOperation("指数趋势查询")
    @PostMapping("/business/index/findIndexTrendData")
    @BusinessLog(title = "指数趋势查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findIndexTrendData(@RequestBody QueryIndexParam param) {
        JSONObject result = new JSONObject();
        List<BiIndexDataSum> indexTrendList = indexDataSumService.findIndexDataListByParams(param);
        result.put("indexTrendList", indexTrendList);
        return new SuccessResponseData(result);
    }

}
